#ifndef QINPUTHOOKS_H
#define QINPUTHOOKS_H

#include <QObject>
#include <QKeySequence>
#include <QPair>
#include <QLoggingCategory>
#include <QKeyEvent>

class KeyEvent : public QKeyEvent
{
 public:
    KeyEvent() : QKeyEvent(QEvent::None, 0, Qt::NoModifier){}
    KeyEvent(QKeyEvent &e)
        : QKeyEvent(e.type(), e.key(), e.modifiers(),
                    e.nativeScanCode(), e.nativeVirtualKey(),
                    e.nativeModifiers(), e.text(),
                    e.isAutoRepeat(), e.count())
        {}
    virtual ~KeyEvent(){}
    WId wid = 0; // native window id
    QString wids;
    qulonglong time = 0;
    QString wtitle; // focus window title
    WId fwid = 0; // focus window id
};
Q_DECLARE_METATYPE(KeyEvent);

typedef QMap<QString,QVariant> KeyEventX;

//! A class to define global, systemwide Hotkeys
class QInputHooks : public QObject
{
	Q_OBJECT

public:
	//! Constructor
	explicit QInputHooks(QObject *parent = Q_NULLPTR);
	//! Destructor
	~QInputHooks();

	static QInputHooks *instance();

    void initNativeHook();
    void activateNativeKeyEvent(void *nev);
    KeyEvent nativeKeyEvent(void *nev);

    void *nativeCtx;

 public:
    static KeyEvent keyEventFromx(KeyEventX ex);
    static KeyEventX keyEventTox(KeyEvent &e);

public slots:

signals:
    void KeyDown(KeyEvent e);
    void KeyDown2(KeyEventX e);
    void KeyUp(KeyEvent e);
    void MouseAll();

private:
};

Q_DECLARE_LOGGING_CATEGORY(logQInputHooks)

#define NATIVE_INSTANCE(ClassName)                      \
	Q_GLOBAL_STATIC(ClassName, hookInstance)           \
                                                        \
	QInputHooks *QInputHooks::instance()  \
	{                                                   \
		return hookInstance;                           \
	}

#endif // QINPUTHOOKS_H
